'''
Created on 15.12.2010

@author: imagovrn
'''

class GraphWrapper(object):
    def __init__(self, graph):
        assert graph is not None
        
        self._graph = graph
        self._map = None
        
    def node_count(self):
        return len(self._graph.nodes())
    
    def reset_node_map(self):
        self._map = None
    
    def node_map(self):
        if self._map == None:
            self._map = self._calculate_node_map()
        return self._map
    
    def _calculate_node_map(self):
        result = {}
        nodes = self._graph.nodes()
        for i in xrange(len(nodes)):
            result[i + 1] = nodes[i]
        return result
    
    @property
    def graph(self):
        return self._graph
